<?php
/**
 * GioCMS
 * 
 * LICENSE
 *
 * This source file is subject to the GNU GENERAL PUBLIC LICENSE Version 2 
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.gnu.org/licenses/gpl-2.0.txt
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@ninhgio.com so we can send you a copy immediately.
 * 
 * @copyright	Copyright (c) 2010-2011 GioCMS (http://cms.ninhgio.com)
 * @license		http://www.gnu.org/licenses/gpl-2.0.txt GNU GENERAL PUBLIC LICENSE Version 2
 * @author		NinhGio - ninhgio@gmail.com
 * @since		1.0
 */

class Modules_News_Hooks_Articlerelates_Hook extends Gio_Core_Hook
{
	public static function show($articleId = null)
	{
		$view = Gio_Core_View::getInstance();
		
		$relateArticles = Modules_News_Services_ArticleRelate::getArticles($articleId);

		$view->relateArticles = $relateArticles; 
		
		$viewFile = TEMPLATE_DIR . DS . $view->APP_TEMPLATE . DS . 'modules'
							 . DS . 'news' . DS . '_partial' . DS . '_articleRelate.phtml';
		echo $view->render($viewFile, true);
	}
	
	public static function add($articleId)
	{
		$request       	  = Gio_Core_Request::getInstance();
		$articleRelateIds = $request->getParam('relateArticleIds');
		if ($articleId && !empty($articleRelateIds)) {
			$conn = Gio_Db_Connection::getConnection();
			$dao = new Modules_News_Models_Mysql_Article();
			$dao->addToRelateArticles($articleId, $articleRelateIds);
		}
	}
}
